// pages/profile/profile.js
const app = getApp()
Page({
  data: {
    requestUrl: app.globalData.requestUrl,
    userInfo: {
    },
    menuItems: [{
        icon: '/images/edit.png',
        title: '修改信息',
        action: 'editProfile',
        color: '#4a90e2'
      },
      {
        icon: '/images/login.png',
        title: '退出登录',
        action: 'logout',
        color: '#ff4d4f'
      }
    ]
  },
  onShow(){
    let that=this;
    wx.request({
      url: app.globalData.requestUrl + '/user/selectById?id='+wx.getStorageSync('user').id,
      method: 'post',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          userInfo: res.data.user
        });
      }
    });
  },
  handleMenuTap(e) {
    const action = e.currentTarget.dataset.action
    if (action === 'editProfile') {
      wx.navigateTo({
        url: '/pages/userInfo/index'
      })
    } else if (action === 'logout') {
      wx.showModal({
        title: '确认退出',
        content: '确定要退出当前账号吗？',
        success: res => {
          if (res.confirm) {
            wx.removeStorageSync('token')
            wx.reLaunch({
              url: '/pages/login/index'
            })
          }
        }
      })
    }
  },



})